<template>
  <z-space direction="vertical" :size="12" style="width: 400px">
    <z-date-picker
      v-model:value="value1"
      format="YYYY-MM-DD HH:mm:ss"
      :disabled-date="disabledDate"
      :disabled-time="disabledDateTime"
      :show-time="{ defaultValue: dayjs('00:00:00', 'HH:mm:ss') }"
    />
    <z-date-picker v-model:value="value2" :disabled-date="disabledDate" picker="month" />
    <z-range-picker v-model:value="value3" :disabled-date="disabledDate" />
    <z-range-picker
      v-model:value="value4"
      style="width: 400px"
      :disabled-date="disabledDate"
      :disabled-time="disabledRangeTime"
      :show-time="{
        hideDisabledOptions: true,
        defaultValue: [dayjs('00:00:00', 'HH:mm:ss'), dayjs('11:59:59', 'HH:mm:ss')],
      }"
      format="YYYY-MM-DD HH:mm:ss"
    />
  </z-space>
</template>
<script>
import { defineComponent, ref } from 'vue'
import dayjs from 'dayjs'

export default defineComponent({
  name: 'DatePickerDemo7',
  setup(){
    const range = (start, end) => {
      const result = []

      for (let i = start; i < end; i++) {
        result.push(i)
      }

      return result
    }

    const disabledDate = current => {
      // Can not select days before today and today
      return current && current < dayjs().endOf('day')
    }

    const disabledDateTime = () => {
      return {
        disabledHours: () => range(0, 24).splice(4, 20),
        disabledMinutes: () => range(30, 60),
        disabledSeconds: () => [55, 56]
      }
    }

    const disabledRangeTime = (_, type) => {
      if (type === 'start') {
        return {
          disabledHours: () => range(0, 60).splice(4, 20),
          disabledMinutes: () => range(30, 60),
          disabledSeconds: () => [55, 56]
        }
      }

      return {
        disabledHours: () => range(0, 60).splice(20, 4),
        disabledMinutes: () => range(0, 31),
        disabledSeconds: () => [55, 56]
      }
    }

    return {
      dayjs,
      value1: ref(),
      value2: ref(),
      value3: ref(),
      value4: ref(),
      disabledDate,
      disabledDateTime,
      disabledRangeTime
    }
  }
})
</script>
